#ifndef MUTISIGNALDECODE_H
#define MUTISIGNALDECODE_H
#include <QList>
#include "../DemodulatorStruct.h"
#include "../mBPSK_Demodulator/BPSK_Demodulator.h"
#include "../mCommon/MOD.h"
#include "../fftw3.h"
#include "SerialUtil.h"
#include <math.h>
#include <QApplication>



QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

#define SEND_PARAMS_SIZE (13)
class MutiSignalDecode : public QObject
{
    Q_OBJECT
public:
    explicit MutiSignalDecode(QObject *parent = nullptr);

    //存放渲染解调数据;
    double EqErr_PriCh_Temp[SERIAL_PORT_COUNT][EQ_ALL_ERR_LEN]; //均衡后误差
    double EqSig_PriCh_Temp_I[SERIAL_PORT_COUNT][EQ_ALL_ERR_LEN]; //DFE均衡后数据-Re
    double EqSig_PriCh_Temp_Q[SERIAL_PORT_COUNT][EQ_ALL_ERR_LEN]; //DFE均衡后数据-Im
    double MseqCorrOut_PriCh_Temp[SERIAL_PORT_COUNT][MseqCorrOut_PriCh_TempSize]; //M序列相关
    double DataPrimary_Temp[SERIAL_PORT_COUNT][DataPrimary_BUF_SIZE]; //AD采样数据
    double Data_SignalDenoise[SERIAL_PORT_COUNT][DataPrimary_BUF_SIZE]; //预滤波数据
    double DataPrimary_Fre_Temp[SERIAL_PORT_COUNT][DataPrimary_BUF_SIZE/2]; //采样数据频谱
    double Farrow_Temp[SERIAL_PORT_COUNT][FRROR_TEMP_LEN] = {{0},{0}}; //采样数据频谱


    void init_Param(int hzType); //初始化参数
    void demodule(int hzType);    //调用解调模块
    void dbpsk_demodule(int hzType);
    void free_Param();  //释放内存
    void demodule_DecData(int hzType);    //解调数据
    void record_log(QString message);

    PtrProbe  Probe[SERIAL_PORT_COUNT]; //中间数据结构体输入（存储每1秒各模块处理后的数据)
    PtrMudSig  MudSigStand[SERIAL_PORT_COUNT]; //原始通道信号输入

    QString baseUrl = QApplication::applicationDirPath() + "/conf/";
    int frame_counter = 0;
    int  C_DATA_FRAME_LEN_BIT = 543;		//初始数据帧长度，比特.
    int  PressureSensorNum = 1;			//压力传传感器数量
    int save_source_data[SERIAL_PORT_COUNT]; //存储信号源
    double ZoomIn[SERIAL_PORT_COUNT]; //数据放大倍数
    double sys_zgcd[SERIAL_PORT_COUNT]; //钻杆长度
    int selhzType = 1; //系统发送频率选择；默认高频
    QString iniPortType[SERIAL_PORT_COUNT]={"Low","High"};
    PtrDemodParam DemodParam[SERIAL_PORT_COUNT]; //解调器参数结构体
    PtrDemodulatorStruct  DemodulatorS_PriCh[SERIAL_PORT_COUNT]; //BPSK结构体系数输入
signals:
    void sendDeCodeData(QString decData,int hzType);
    void sendDecCode2WorkPlat(QByteArray decData);
private:
    //int CountN[4] = {6250,1953,1250,977};
    double CountN[4] = {12500,5000,2500,10000};
    FILE* INIFileStream[SERIAL_PORT_COUNT];
    FILE* logfile;



    unsigned long int ModuleEnableStatus[SERIAL_PORT_COUNT];
    double  Fc_Hz[SERIAL_PORT_COUNT];// = 125;//载波频率
    double  Rb_bps[SERIAL_PORT_COUNT];// = 25;//数据比特率
    double  Fc_Hz_read[SERIAL_PORT_COUNT];// = 12;//载波频率
    double  Rb_bps_read[SERIAL_PORT_COUNT];// = 3;//数据比特率
    int Actual_Len[SERIAL_PORT_COUNT];// = Rb_bps_int * SAMPNUM_PERSYMBOL;//采样率变换后信号的实际长度.
    double *fft_in[SERIAL_PORT_COUNT];
    fftw_complex *fft_out[SERIAL_PORT_COUNT];
    fftw_plan my_plan[SERIAL_PORT_COUNT];

    //解调相关参数
    FIFO_Dec fifoDec[SERIAL_PORT_COUNT];
    FIFO_Dec_Byte fifoDecByte[SERIAL_PORT_COUNT];
    Cout_Dec countDec[SERIAL_PORT_COUNT];
    QMap<int, QList<double>> sendDecData; //存放解调后的数据
    QMap<int, QList<double>> tempListData; //临时变量
    //发送条件;
    char sendParams[SEND_PARAMS_SIZE][2] = {{1,14},{2,5},{3,6},{4,7},{5,7},{6,6},{7,8},{8,8},{9,10},{10,11},{11,9},{12,10},{13,8}};
    int StateN[SERIAL_PORT_COUNT] = {0};
    double tempRead1[SERIAL_PORT_COUNT] = {0},tempRead2[SERIAL_PORT_COUNT]={0};
     int gnDlPhy_Frame_RxCnt_Intermediate[SERIAL_PORT_COUNT] = {0};
};

#endif // MUTISIGNALDECODE_H
